<?php
/**
 * Introduction: 购物车接口类
 * @author: 王龙
 * @date: 2016/4/13 15:37
 * @email: wanglong@cdlinglu.com
 */

namespace WeChat\Controller\Cart;

use Common\Controller\WeChat\SignController;

class IndexController extends SignController
{

    /**
     * Introduction: 购物车列表
     * @author: 王龙
     * @date: 2016/4/13 15:42
     * @email: wanglong@cdlinglu.com
     */
    public function lists()
    {

        $cart = D('Common/Cart', 'Logic');

        $page = I('post.page', 1);

        outPut($cart::getGoodsData(['uid' => self::$uid], $page), true);//查询购物车所有商品

    }

    /**
     * Introduction: 添加商品到购物车
     * @author: 王龙
     * @date: 2016/4/13 15:42
     * @email: wanglong@cdlinglu.com
     * @notice:  杨陈鹏   2016/04/18 16:16  修改
     */
    public function create()
    {

        $cart_logic = D('Common/Cart', 'Logic');

        $goods_attr_val_ids = I('post.goods_attr_val_ids');

        $goods_id = intval(I('post.goods_id'));
        $goods_num = intval(I('post.goods_num'));

        $data['goods_id'] = $goods_id;
        $data['goods_attr_val_ids'] = $goods_attr_val_ids;
        $data['goods_num'] = $goods_num;
        $data['uid'] = self::$uid;


        //检测库存
        $where['goods_id'] = $goods_id;
        $where['goods_num'] = $goods_num;
        $where['uid'] = self::$uid;

        if ($goods_attr_val_ids) {

            $data['goods_attr_val_ids'] = $goods_attr_val_ids;
            $where['goods_attr_val_ids'] = $goods_attr_val_ids;

        }

        //将数据添加到购物车
        outPut($cart_logic::create($data), true);
    }

    /**
     * Introduction: 移除商品
     * @author: 王龙
     * @date: 2016/4/13 16:42
     * @email: wanglong@cdlinglu.com
     */
    public function delete()
    {

        $cart = D('Common/Cart', 'Logic');

        $ids = I('post.ids');

        outPut($cart::delete($ids, self::$uid));
    }

    /**
     * @introduction: 修改购物车里的商品数量
     * @author: 王龙
     * @date: 2016/4/13 17:11
     * @email: wanglong@cdlinglu.com
     */
    public function update()
    {

        $cart = D('Common/Cart', 'Logic');

        $data = I('post.data');

        $data['uid'] = self::$uid;

        outPut($cart::update($data));
    }

}  